package com.mes.web.controller.cb;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.gson.Gson;
import com.mes.entity.jy.Plandetail;
import com.mes.service.cb.CustomService;
import com.mes.service.jy.ProductPlanDetailServise;
import com.mes.utils.DateJsonValueProcessor;
import com.mes.utils.ResponseUtil;

/**
 * @ClassName:CustomController
 * @Description:自定义controller
 * @Author cb
 * @Date 2018年3月13日上午10:40:33
 * @version 1.0
 */
@Controller
@RequestMapping("custom")
public class CustomController {
	
	@Resource
	private CustomService customService;
	
	@Resource
	private ProductPlanDetailServise productPlanDetailServise;
	/**
	 * 查询所有的生产计划单号
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("/custom_list")
	public void custom_list(HttpServletResponse response) throws Exception {
		
		List<String> strings =customService.custom_list();
		
		ResponseUtil.write(response, new Gson().toJson(strings));
	}
	
	/**
	 * 生产计划单详细
	 * @param prnum 生产计划单号
	 * @throws Exception 
	 */
	@RequestMapping("/custom_listDetail")
	public void custom_listDetail(String prnum,HttpServletResponse response) throws Exception {
		int total = customService.countProductPlanDetail(prnum);
		List<Plandetail> list= customService.selectPlanDetail(prnum);
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
		JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
		jsonObject.put("total", total);
		jsonObject.put("rows", jsonArray);
		ResponseUtil.write(response, jsonObject);
	}
}
